/**
 * Created by zhaojm on 15/3/21.
 */
// 石头
game.Stone = frame.BaseRole.extend({
    //_action_roll : null,

    _object : null,
    ctor:function(){

        this._className = 'game.Stone';

        this._object = ccs.load(res.stone_json);
        this._object.node.runAction(this._object.action);
        this._object.action.setFrameEventCallFunc(this.onFrameEvent);

        this._super();


        this.roll();

    },


    getNode : function(){
        return this._object.node;
    },

    getNodeHeight:function(){
        //cc.log('stone...height...', this._object.node.getChildByName('roll').getContentSize().height);
        return this._object.node.getChildByName('roll').getContentSize().height;
    },

    update : function(dt){
        this._super(dt);

    },

    roll : function(){
        this._object.action.gotoFrameAndPlay(0, 30, true);
    },
    bang : function(){
        this._object.action.gotoFrameAndPlay(30, 45, false);
    },


    doCollidedWithHero : function(){
        if(this._layer._speedUpTimeCount <= 0) {
            var bear = this._layer._bear;
            bear.setScale(bear.getScale() + 0.1);
        }

        this.bang();
        this._layer._hero.strike();

    },

    doCollidedWithBear:function(){
        if(this._layer._bear.getScale() > 0 ) {
            this.bang();
        }else {
            this.removeFromLayer();
        }
    },

    onFrameEvent : function(frame){
        var evnt = frame;
        if(!evnt)
            return;

        var str = evnt.getEvent();

        if (str == "bang_end"){
            evnt.getNode().parent.removeFromParent(true);
        }
    },


});